import Vue from 'vue' //引用vue
import Vuex from 'vuex' //引用vuex
import { getlink } from '@/api/getapi.js'
import { systemM } from './modules/systemM.js'
import { dxysma } from './dxymodules/dxy.js'

Vue.use(Vuex) // 在vue中use(使用)vuex
// 暴露 vuex实例
export default new Vuex.Store({
    state: {
        arr: [
            { cla: 'iconfont icon-tubiao-', text: '首页', style: true },
            { cla: 'iconfont icon-fenlei', text: '分类', style: false },
            { cla: 'iconfont icon-faxian', text: '发现', style: false },
            { cla: 'iconfont icon-xuexi_nor', text: '学习', style: false },
            { cla: 'iconfont icon-boshimao', text: '账号', style: false }
        ],
        brr: [
            { title: '推荐', style: true },
            { title: '免费课', style: false },
            { title: '实战课', style: false },
            { title: '体系课', style: false },
            { title: '专栏', style: false },
            { title: '教程', style: false }
        ],
        text: '我是学习',
        recomarr: [],
        crr: [],
        arrb: [],
        jkqqarr: []
    },
    mutations: {
        arrb(state, payload) {
            state.arrb = payload
        },
        crra(state, payload) {
            state.crr = payload
        },
        // 学习
        learning(state, payload) {
            state.text = payload
        },

        upbrr(state, payload) {
            state.brr.forEach(element => {
                element.style = false
            })
            state.brr[payload].style = !state.brr[payload].style
        },
        uparr(state, payload) {
            state.arr.forEach(element => {
                element.style = false
            })
            state.arr[payload].style = !state.arr[payload].style
        },
        recomarrs(state, payload) {
            state.recomarr = payload
        },
        jkqqarr(state, payload) {
            state.jkqqarr = payload
        }
    },
    actions: {
        xolink(context, payload) {
            getlink(payload.url).then((ok) => {
                context.commit('arrb', ok.data)
            })
        },
        axioslink(context, payload) {
            getlink(payload.url).then((ok) => {
                console.log(ok.data)
                context.commit('crra', ok.data)
            }).then((err) => {
                console.log(err)
            })
        },
        jkqqaxioslink(context, payload) {
            // 发送异步操作   拦截器与数据请求封装
            getlink(payload.url).then((ok) => {
                console.log(ok.data)
                context.commit('jkqqarr', ok.data)
            })
        },
        rercomaxioslink(context, payload) {
            // 发送异步操作   拦截器与数据请求封装
            getlink(payload.url).then((ok) => {
                console.log(ok.data)
                context.commit('recomarrs', ok.data)
            })
        },
    },
    // 异步操作    拦截器与数据请求封装
    modules: {
        systemM,
        dxysma
    },
})